package mycoffee.order.xmlhandler;

import java.util.ArrayList;

import mycoffee.order.model.Table;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import android.text.TextUtils;

public class TablesHandler extends DefaultHandler {
	/** list of categories. */
	private ArrayList<Table> mTables;

	public TablesHandler() {
		mTables = new ArrayList<Table>();
	}

	public ArrayList<Table> getResult() {
		return mTables;
	}

	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {
		super.startElement(uri, localName, qName, attributes);
		try {
			if (TextUtils.equals(localName, XmlConstants.TABLE)) {
				Table table = new Table();
				mTables.add(table);
				table.setId(Integer.parseInt(attributes
						.getValue(XmlConstants.ID)));
				table.setName(attributes.getValue(XmlConstants.NAME));
				table.setName_vi(attributes.getValue(XmlConstants.NAME_VN));
				table.setName_en(attributes.getValue(XmlConstants.NAME_EN));
				table.setName_de(attributes.getValue(XmlConstants.NAME_DE));
			}
		} catch (Exception e) {
		}

	}

	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {
		super.endElement(uri, localName, qName);
	}

}
